/*
 * Powered By cuichen
 * Since 2014 - 2017
 */package com.seeyoui.kensite.framework.cms.portletArticle.service;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.seeyoui.kensite.common.base.service.BaseService;

import java.util.*;

import com.seeyoui.kensite.common.base.domain.EasyUIDataGrid;
import com.seeyoui.kensite.common.base.service.BaseService;
import com.seeyoui.kensite.common.exception.CRUDException;
import com.seeyoui.kensite.common.util.*;
import com.seeyoui.kensite.common.constants.StringConstant;
import com.seeyoui.kensite.framework.cms.portletArticle.domain.PortletArticle;
import com.seeyoui.kensite.framework.cms.portletArticle.persistence.PortletArticleMapper;

/**
 * PortletArticle
 * @author cuichen
 * @version 2.0
 * @since 1.0
 * @date 2017-12-28
 */

@Service
public class PortletArticleService extends BaseService {
	
	@Autowired
	private PortletArticleMapper portletArticleMapper;

	/**
	 * 根据ID查询单条数据
	 * @param id
	 * @return
	 * @throws CRUDException
	 */
	public PortletArticle findOne(String id) throws CRUDException{
		return portletArticleMapper.findOne(id);
	}
	
	/**
	 * 查询数据集合
	 * @param portletArticle
	 * @return
	 * @throws CRUDException
	 */
	public List<PortletArticle> findList(PortletArticle portletArticle) throws CRUDException {
		return portletArticleMapper.findList(portletArticle);
	}
	
	/**
	 * 查询所有数据集合
	 * @param portletArticle
	 * @return
	 * @throws CRUDException
	 */
	public List<PortletArticle> findAll(PortletArticle portletArticle) throws CRUDException {
		return portletArticleMapper.findAll(portletArticle);
	}
	
	/**
	 * 查询数据总数
	 * @param portletArticle
	 * @return
	 * @throws CRUDException
	 */
	public int findTotal(PortletArticle portletArticle) throws CRUDException {
		return portletArticleMapper.findTotal(portletArticle);
	}
	
	/**
	 * 查询数据总数排除当前数据
	 * @param portletArticle
	 * @return
	 * @throws CRUDException
	 */
	public int findExTotal(PortletArticle portletArticle) throws CRUDException {
		return portletArticleMapper.findExTotal(portletArticle);
	}
	
	/**
	 * 数据新增
	 * @param portletArticle
	 * @throws CRUDException
	 */
	public void save(PortletArticle portletArticle) throws CRUDException{
		portletArticle.preInsert();
		portletArticleMapper.save(portletArticle);
	}
	
	/**
	 * 数据新增，将网络抓取的文章写入数据库，绕过权限控制直接写库
	 * 使用地方：用于CrawlerJob的定时抓取任务
	 * @param portletArticle
	 * @throws CRUDException
	 */
	public void saveByCrawler(PortletArticle portletArticle) throws CRUDException{
		portletArticle.setId(GeneratorUUID.getId());
		portletArticle.setCreateDate(new Date());
		portletArticleMapper.save(portletArticle);
	}
	
	/**
	 * 数据修改
	 * @param portletArticle
	 * @throws CRUDException
	 */
	public void update(PortletArticle portletArticle) throws CRUDException{
		portletArticle.preUpdate();
		portletArticleMapper.update(portletArticle);			
	}
	
	/**
	 * 数据删除
	 * @param listId
	 * @throws CRUDException
	 */
	public void delete(List<String> listId) throws CRUDException {
		portletArticleMapper.delete(listId);
	}
	
	/**
	 * 数据假删除
	 * @param portletArticle
	 * @throws CRUDException
	 */
	public void remove(PortletArticle portletArticle) throws CRUDException{
		portletArticle.preUpdate();
		portletArticleMapper.remove(portletArticle);			
	}
	
}